import Vue from 'vue'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
// import VueLazyLoad from 'vue-lazyload'
import VueCookie from 'vue-cookie'
import { Message } from 'element-ui'
Vue.prototype.$message = Message;
// import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import { IMGBASEURL } from '@/api/index'


Vue.prototype.IMGBASEURL = IMGBASEURL;

Vue.use(ElementUI)
// axios.defaults.baseURL = '/api';
axios.defaults.timeout = 8000;
//拦截器
axios.interceptors.response.use(function(response){
  let res = response.data;
  let path = location.hash;
  if(res.status == 200){
    return res;
  }else if(res.status == 401){
    if (path != '#/index'){
      window.location.href = '/#/login';
    }
    sessionStorage.removeItem("Authorization")
    // this.$message.warning(res.message);
    Message.warning(res.message);
    return Promise.reject(res);
  }else{
    // this.$message.warning(res.message);

    Message.warning(res.message);
    return Promise.reject(res);
  }
},(error)=>{
  let res = error.response;
  if (res.data.status === 1000) {
    router.push({path: '/applylicense'})
  }else if(res.status == 401){
    let path = location.hash;
    if (path != '#/index'){
      router.push('/login')
    }
    sessionStorage.removeItem("Authorization")
    // this.$message.warning(res.message);
    Message.warning(res.message);
    return Promise.reject(res);
  }else{
    Message.error(res.data.message);
  }
  return Promise.reject(error);
});

axios.interceptors.request.use((request)=>{
  request.headers.common = {
    'Authorization' : sessionStorage.getItem('Authorization'),
  };
  return request;
});


Vue.use(VueAxios,axios);
Vue.use(VueCookie);
// Vue.use(VueLazyLoad,{
//   loading:'/imgs/loading-svg/loading-bars.svg'
// })

Vue.config.productionTip = false

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
